package com.qolome.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
import com.baomidou.mybatisplus.extension.injector.methods.LogicDeleteByIdWithFill;
import com.qolome.metadata.DeleteAllMethod;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author Qolome
 * @version V1.0
 * @Description SQL注入
 * @date 2020年 01月12日 22:18:06
 */
@Component
public class MySqlinjector extends DefaultSqlInjector {


    @Override
    public List<AbstractMethod> getMethodList (Class<?> mapperClass) {
        List<AbstractMethod> methodList = super.getMethodList (mapperClass);
        methodList.add (new DeleteAllMethod ());
        methodList.add (new InsertBatchSomeColumn (tableFieldInfo ->
                !tableFieldInfo.isLogicDelete ()
                &&!tableFieldInfo.getColumn ().equals ("age")
        ));
        methodList.add (new LogicDeleteByIdWithFill ());
        methodList.add (new AlwaysUpdateSomeColumnById (t->
                !t.getColumn ().equals ("name")
                ));
        return  methodList;
    }
}
